package com.yixing.tech.wms.controller;

import com.yixing.tech.common.base.BaseControl;
import com.yixing.tech.common.base.BaseResponse;
import com.yixing.tech.common.base.Rs;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.wms.param.InitParam;
import com.yixing.tech.wms.service.InitClearService;
import com.yixing.tech.common.entity.WCSTaskCallbackVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 初始化
 *
 * @author yixing tech
 * @since 1.0.0
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping(value = "/clear")
public class InitClearController extends BaseControl {

    @Autowired
    private InitClearService initService;


    @PostMapping("/out")
    public Rs<Object> save(@RequestBody InitParam param) throws BusinessException {
        return Rs.ok(initService.initClear(param.getWorkCode()));
    }

    @PostMapping("/wcs/callback")
    public Rs<Object> callback(@RequestBody WCSTaskCallbackVO callbackVO) throws BusinessException {
        log.info("清除下架 callback, 请求参数:{}", callbackVO);

        initService.handleCallback(callbackVO.getTaskCode(), callbackVO.getMethod(),
                callbackVO.getCurrentPositionCode(), callbackVO.getPodCode());

        BaseResponse<Object> response = new BaseResponse<>();
        response.setCode(1000);
        response.setDesc("任务节点反馈接收成功!");
        return response;
    }


}
